<?php
$upload_path="../u/";//上传目录
$overwrite="1";//是否覆盖1表示覆盖0表示不覆盖
if (isset($_FILES["Filedata"]) && is_uploaded_file($_FILES["Filedata"]["tmp_name"]) && $_FILES["Filedata"]["error"] == 0) {
    //上传文件赋值给$upload_file
    $upload_file=$_FILES["Filedata"];
    //获取文件类型
    $file_info=pathinfo($upload_file["name"]);
    //获取文件扩展名
    $file_ext=$file_info["extension"];
    //设置路径方式
    //建立文件夹
    create($upload_path);
	//$upload_file['name']=substr(md5($upload_file['name']),12,16).'.'.$file_ext
    //设置默认服务端文件名
    $upload_file['filename']=$upload_path.$upload_file['name'];
    //检查文件是否存在
    if(file_exists($upload_file['filename'])){
        if($overwrite){
            @unlink($upload_file['filename']);
        }else{
            $j=0;
            do{
                $j++;
                $temp_file=str_replace('.'.$file_ext,'('.$j.').'.$file_ext,$upload_file['filename']);
            }while (file_exists($temp_file));
            $upload_file['filename']=$temp_file;
            unset($temp_file);
            unset($j);
        }
    }
    if(@move_uploaded_file($upload_file["tmp_name"],$upload_file["filename"])){
        //下面插入一段把路径保存到数据库中的代码;
        // Create a pretend file id, this might have come from a database.
        //产生一个上传文件id,这可能来自数据库;
        //这里必需echo内容可以是文件id或许数据库中的id，不然程序会出现错误，没有内容传回到index.php表单中的hidFileID中
        echo $upload_file["filename"];
    }else{
        echo '';
    }
} else {
    echo ' '; // I have to return something or SWFUpload won't fire uploadSuccess
}
//建立文件夹
function create($dir)
{
    if (!is_dir($dir))
    {
        $temp = explode('/',$dir);
        $cur_dir = '';
        for($i=0;$i<count($temp);$i++)
        {
            $cur_dir .= $temp[$i].'/';
            if (!is_dir($cur_dir))
            {
                @mkdir($cur_dir,0777);
                @fopen("$cur_dir/index.htm","a");
            }
        }
    }
}

?><script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-35723104-3', 'yooooo.us');
  ga('send', 'pageview');

</script>